//
//  NSMutableAttributedString+RichText.m
//  QZMJ
//
//  Created by 腾程－ios1 on 16/12/9.
//  Copyright © 2016年 曾少伟. All rights reserved.
//

#import "NSMutableAttributedString+RichText.h"

@implementation NSMutableAttributedString (RichText)
+ (instancetype)attributedStringWith:(UIImage *)image {
    NSTextAttachment *attachment = [[NSTextAttachment alloc]init];
    attachment.image = image;
    attachment.bounds = CGRectMake(0,0,image.size.width/2, image.size.height/2);
    NSMutableAttributedString *attachmentStr = (NSMutableAttributedString *)[NSMutableAttributedString attributedStringWithAttachment:attachment];
    return attachmentStr;
}

+ (instancetype)attributedStringWith:(UIImage *)image
                           imageSize:(CGSize)imgageSize
{
    NSTextAttachment *attachment = [[NSTextAttachment alloc]init];
    attachment.image = image;
    attachment.bounds = CGRectMake(0,0,imgageSize.width, imgageSize.height);
    NSMutableAttributedString *attachmentStr = (NSMutableAttributedString *)[NSMutableAttributedString attributedStringWithAttachment:attachment];
    return attachmentStr;
}

+ (instancetype)attributedStringForHtmlWithString:(NSString *)str {
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithData:[str dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
    return attributedString;
}
@end
